package xyz.shenmegui.foodcheckserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import xyz.shenmegui.foodcheckserver.DO.DailyRecommend;
import xyz.shenmegui.foodcheckserver.DO.Menu;
import xyz.shenmegui.foodcheckserver.mapper.DailyRecommendMapper;
import xyz.shenmegui.foodcheckserver.mapper.MenuMapper;
import xyz.shenmegui.foodcheckserver.service.DailyRecommendService;
import xyz.shenmegui.foodcheckserver.service.MenuService;
import xyz.shenmegui.foodcheckserver.utils.DateUtils;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class DailyRecommendServiceImpl implements DailyRecommendService {

    @Autowired
    private MenuService menuService;
    @Autowired
    private DailyRecommendMapper dailyRecommendMapper;

    @Override
    public List<Menu> getRecommend(Integer userId, LocalDate date) {
        LambdaQueryWrapper<DailyRecommend> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DailyRecommend::getUid, userId);
        queryWrapper.eq(DailyRecommend::getDate, date);
        DailyRecommend dailyRecommend = dailyRecommendMapper.selectOne(queryWrapper);
        if (dailyRecommend == null || dailyRecommend.getSeedId() == null) {
            return new ArrayList<>();
        }
        return menuService.getMenuBySeedId(dailyRecommend.getSeedId());
    }

    @Override
    public void insertRecommend(DailyRecommend dailyRecommend) {
        dailyRecommendMapper.insert(dailyRecommend);
    }

}
